<template>
	<view class="record">
		<view class="head">
			<view class="head_l">
				<view class="head_l_1">余额（元）</view>
				<view class="head_l_2">{{balance}}</view>
			</view>
			<view class="head_r" @click="jump_cash">提现</view>
		</view>
		<None v-if="list_empty"></None>
		<block v-else v-for="(item, index) of list" :key="index">
			<view class="list">
				<view class="list_01">
					<view class="list_01_l">{{ item.type }}</view>
					<view class="list_01_r">-{{ item.money }}</view>
				</view>
				<view class="list_02">
					<view class="list_01_l">{{ item.time }}</view>
					<view class="list_01_r" v-if="item.state == 0">处理中</view>
					<view class="" v-if="item.state == 1">交易成功</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	import {
		mapActions
	} from 'vuex';
	import None from '@/components/qy/none.vue';
	export default {
		components: {
			None
		},
		data() {
			return {
				list: [],
				list_empty: false,
				bankName: '',
				balance: 0.00
			};
		},
		onLoad() {
			this.getCashList();
			//获取余额
			uni.showLoading({
				mask: true
			})
			this.rewardSummary().then(res => {
				uni.hideLoading();
				if (res.code == 0) {
					this.balance = res.data.rewardSumMoney - res.data.cashSumMoney;
					this.balance = this.balance.toFixed(2);
				}
			}).catch(err => {
				console.log('err', err)
			})
		},
		onShareAppMessage(res) {
			let referrer = uni.getStorageSync('referrer');
			console.log('referrer', referrer);
			if (referrer) {
				return {
					title: '恒鲜惠美食在线',
					path: '/pages/menu/menu?referrer=' + referrer,
					imageUrl: require('static/images/menu/banner.jpeg')
				}
			}
		},
		methods: {
			...mapActions(['cashList', 'rewardSummary']),
			jump_cash() {
				uni.navigateTo({
					url: '/pages/user/cash/cash'
				});
			},
			getCashList() {
				uni.showLoading({
					mask: true
				});
				this.cashList().then(
					res => {
						if (!res.data.length) {
							this.list_empty = true;
						}
						this.list = res.data || [];
						console.log(this.list);
						uni.hideLoading();
						uni.stopPullDownRefresh();
					},
					err => {
						uni.stopPullDownRefresh();
					}
				);
			}
		},
		onPullDownRefresh() {
			this.getCashList();
		}
	};
</script>

<style lang="scss">
	.record {
		font-size: 14px;

		.head {
			background-color: #ff4d4d;
			padding: 20px 10px;
			display: flex;
			justify-content: space-between;

			.head_l {
				color: #fff;

				.head_l_2 {
					font-size: 22px;
					padding-top: 10px;
				}
			}

			.head_r {
				background-color: #fff;
				color: #fd6766;
				height: 30px;
				line-height: 30px;
				width: 90px;
				text-align: center;
				border-radius: 20px;
				margin-top: 15px;
			}
		}

		.list {
			margin: 15px 10px;
			box-shadow: 0px 0px 10px #ededed;
			border-radius: 5px;
			padding: 15px 10px;

			.list_01 {
				display: flex;
				justify-content: space-between;
				font-size: 16px;
				font-weight: 600;
				padding-bottom: 10px;
			}

			.list_02 {
				display: flex;
				justify-content: space-between;
				color: #9a9a9a;

				.list_01_r {
					color: #fc4f50;
				}
			}
		}
	}
</style>
